package database;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

public class ConnexionJavaDB {

	private static DataSource dataSource;
	
	public static DataSource getInstance () {
		
		if(dataSource == null) {
			Context initCtx;
			try {
				initCtx = new InitialContext();
				dataSource = (DataSource) initCtx.lookup("java:comp/env/jdbc/dbpizza");
			} catch (NamingException e) {
				System.err.println("Datasource indisponible");
			}
		}
		
		return dataSource;
	}
	
}
